//------------------------------------------------------------------------------
// <pcdd-entitiy>
//     彩票主流业务类库
//     方案业务对象
// </pcdd-entitiy>
//------------------------------------------------------------------------------ 

using CL.Enum.Common;
using CL.Game.DAL;
using CL.Game.Entity;
using CL.Json.Entity;
using CL.Json.Entity.WebAPI;
using CL.Redis.BLL;
using CL.Tools.MSMQManager;
using CL.View.Entity.Game;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using CL.Tools.Common;
using CL.View.Entity.Interface;
using CL.Enum.Common.Lottery;
using CL.Game.BLL.View;
using CL.View.Entity.Coupons;
using CL.Enum.Common.Status;
using CL.Enum.Common.Type;

namespace CL.Game.BLL
{

    /// <summary>
    /// SchemesBLL 业务
    /// </summary>
    public class SchemesBLL
    {
        SchemesDAL dal = new SchemesDAL(DbConnectionEnum.CaileGame);
        Log log = new Log("SchemesBLL");

        /// <summary>
        /// 查询对象
        /// </summary>
        /// <param name="SchemeID"></param>
        /// <returns></returns>
        public SchemesEntity QueryEntity(long SchemeID)
        {
            return dal.QueryEntity(SchemeID);
        }
        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <param name="SchemeID"></param>
        /// <returns></returns>
        public bool Exists(long SchemeID)
        {
            return dal.Exists(SchemeID);
        }
        /// <summary>
        /// 设置中奖方案
        /// </summary>
        /// <returns></returns>
        public bool SetWinMoney(long SchemeID, string AllValues, ref string ReturnDescription)
        {
            return dal.SetWinMoney(SchemeID, AllValues, ref ReturnDescription);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public List<udv_SchemesMain> QueryListByPage(int LotteryCode, int iState, int iWinState, string StartTime, string EndTime, string IsuseName, string SchemeNumber, string UserName, string orderby, int pageSize, int pageIndex,
            ref int recordCount, ref long SumMoney, ref long WinSumMoney)
        {
            return dal.QueryListByPage(LotteryCode, iState, iWinState, StartTime, EndTime, IsuseName, SchemeNumber, UserName, orderby, pageSize, pageIndex,
            ref recordCount, ref SumMoney, ref WinSumMoney);
        }
        /// <summary>
        /// 处理期号截止没有拆票投注的方案
        /// </summary>
        /// <param name="SchemeID"></param>
        /// <returns></returns>
        public bool IsuseStopRevokeSchemes(int LotteryCode)
        {
            try
            {
                string TemplateStr = new TemplateConfigBLL().QueryRevokePushTemplate();
                if (string.IsNullOrEmpty(TemplateStr))
                    return false;
                List<udv_RevokeSchemes> Entitys = dal.IsuseStopRevokeSchemes(LotteryCode);
                foreach (udv_RevokeSchemes Entity in Entitys)
                {
                    var Str = string.Format(TemplateStr, Entity.name, Common.GetDescription((LotteryInfo)LotteryCode), Entity.issue, Entity.num, (Entity.amount / 100).ToString("C"));
                    #region 发短信
                    try
                    {
                        if (!string.IsNullOrEmpty(Entity.mobile))
                            SMS.SendModel(Entity.mobile, Str);
                    }
                    catch (Exception ex)
                    {
                        new Log("Push").Write("撤单短信推送错误：" + ex.Message, true);
                    }
                    #endregion
                    #region 发推送
                    try
                    {
                        //百度推送
                        new UsersPushBLL().PushMessager_Android_Single(Entity.uuid, "系统撤单", Str, string.Empty);
                    }
                    catch (Exception ex)
                    {
                        new Log("Push").Write("撤单环信推送错误：" + ex.Message, true);
                    }
                    #endregion
                    this.OutApply(Entity.ssid, 0, true, DateTime.Now);
                }
                return true;
            }
            catch (Exception ex)
            {
                log.Write("处理期号截止没有拆票投注的方案报错：" + ex.StackTrace, true);
                return false;
            }
        }
        /// <summary>
        /// 更新发送状态
        /// </summary>
        /// <param name="SchemeID"></param>
        /// <returns></returns>
        public bool ModifySendOut(long SchemeID)
        {
            return dal.ModifySendOut(SchemeID);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="LotteryCode"></param>
        /// <param name="IsuseName"></param>
        /// <returns></returns>
        public List<SchemesEntity> QueryEntity(int LotteryCode, string IsuseName)
        {
            return dal.QueryEntity(LotteryCode, IsuseName);
        }
        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int ModifyEntity(SchemesEntity entity)
        {
            return dal.ModifyEntity(entity);
        }

        /// <summary>
        /// 方案跟单
        /// </summary>
        /// <returns></returns>
        public long FollowBetting(long UserID, long SchemeID, string IsuseName, string SchemeNumber)
        {
            return dal.FollowBetting(UserID, SchemeID, IsuseName, SchemeNumber);
        }

        /// <summary>
        /// 报表：彩票投注查询
        /// </summary>
        /// <param name="StartTime">起止时间</param>
        /// <param name="EndTime">起止时间</param>
        /// <param name="UserID">用户ID</param>
        /// <param name="UserName">用户账号</param>
        /// <param name="LotteryCode">彩种</param>
        /// <param name="SchemeStatus">状态</param>
        /// <param name="SchemeNumber">订单编号</param>
        /// <param name="PrintOutType">出票商</param>
        /// <param name="PageIndex">当前页</param>
        /// <param name="PageSize">页大小</param>
        /// <param name="RecordAmount">投注金额</param>
        /// <param name="RecordCount">查询条数</param>
        /// <returns></returns>
        public List<udv_BuyLotReport> QueryBuyLotReport(DateTime StartTime, DateTime EndTime, long UserID, string UserName, int LotteryCode, int SchemeStatus, string SchemeNumber, int PrintOutType, int PageIndex, int PageSize, ref long RecordAmount, ref int RecordCount)
        {
            return dal.QueryBuyLotReport(StartTime, EndTime, UserID, UserName, LotteryCode, SchemeStatus, SchemeNumber, PrintOutType, PageIndex, PageSize, ref RecordAmount, ref RecordCount);
        }

        #region 自定义方法
        /// <summary>
        /// 投注
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="UserCode"></param>
        /// <param name="LotteryCode"></param>
        /// <param name="IsuseNum"></param>
        /// <param name="BeginTime"></param>
        /// <param name="EndTime"></param>
        /// <param name="BuyType"></param>
        /// <param name="Amount"></param>
        /// <param name="RoomCode"></param>
        /// <param name="BetData"></param>
        /// <param name="ChaseData"></param>
        /// <returns></returns>
        public JsonResult Bet(long UserCode, int LotteryCode, string IsuseNum, string BeginTime, string EndTime, short BuyType, long Amount, string RoomCode, string BetData, string ChaseData, string Coupons, int PaymentType, long Gold)
        {
            JsonResult result = null;
            try
            {
                #region 验证彩种是否停售
                var lots = new SystemRedis().ApplyLotteryDataRedis();
                if (lots == null || lots.Count == 0)
                    lots = new LotteriesBLL().SystemLottyData();
                //Redis数据匹配
                var lotteryEntity = lots.Where(w => w.LotteryCode == LotteryCode).FirstOrDefault();

                if (lotteryEntity != null && lotteryEntity.LotteryStatus == 4)  //LotteryStatus = 4 停售
                    return new JsonResult()
                    {
                        Code = (int)ResultCode.LotStop,
                        Msg = Common.GetDescription(ResultCode.LotStop)
                    };
                #endregion
                bool IsSuccess = true;
                DateTime BTime = DateTime.Now, ETime = DateTime.Now;
                try
                {
                    BTime = DateTime.ParseExact(BeginTime, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                    ETime = DateTime.ParseExact(EndTime, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                }
                catch
                {
                    IsSuccess = false;
                }
                if (!IsSuccess)
                {
                    result = new JsonResult()
                    {
                        Code = (int)ResultCode.RequestHasFailed,
                        Msg = Common.GetDescription(ResultCode.RequestHasFailed)
                    };
                }
                else
                {
                    SchemesEntity Entity = new SchemesEntity();
                    try
                    {
                        //string NumberNew = Utils.UrlDecode(BetData.Replace("\\\"", "\""));
                        string NumberNew = (BetData.Replace("\\\"", "\""));
                        List<udv_SchemeBetData> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<udv_SchemeBetData>>(NumberNew);

                        #region 追号
                        udv_Tasks TasksDetails = null;
                        if (BuyType == 1)
                        {
                            //TasksDetails = Newtonsoft.Json.JsonConvert.DeserializeObject<udv_Tasks>(Utils.UrlDecode(ChaseData));
                            TasksDetails = Newtonsoft.Json.JsonConvert.DeserializeObject<udv_Tasks>((ChaseData));
                        }
                        #endregion
                        if (list == null || list.Count == 0)
                        {
                            return new JsonResult()
                            {
                                Code = (int)ResultCode.BettingInfoNull,
                                Msg = Common.GetDescription(ResultCode.BettingInfoNull)
                            };
                        }

                        int BetType = 0;
                        bool IsSplit = false;
                        List<udv_Parameter> RetuList = new List<udv_Parameter>();
                        List<udv_Coupons> CouponsEntitys = null;
                        #region 支付金额验证
                        long TotalMoney = 0; //订单总额
                        switch (PaymentType)
                        {
                            case (int)PaymentTypeEnum.Balance:
                                TotalMoney = Amount;
                                break;
                            case (int)PaymentTypeEnum.Film:
                                CouponsEntitys = Newtonsoft.Json.JsonConvert.DeserializeObject<List<udv_Coupons>>(Coupons);
                                TotalMoney = CouponsEntitys.Sum(s => s.ba);
                                break;
                            case (int)PaymentTypeEnum.Gold:
                                TotalMoney = (Gold / 1000) * 100;
                                break;
                            case (int)PaymentTypeEnum.BalanceToFilm:
                                CouponsEntitys = Newtonsoft.Json.JsonConvert.DeserializeObject<List<udv_Coupons>>(Coupons);
                                TotalMoney = Amount + CouponsEntitys.Sum(s => s.ba);
                                break;
                            case (int)PaymentTypeEnum.BalanceToGold:
                                TotalMoney = Amount + ((Gold / 1000) * 100);
                                break;
                            case (int)PaymentTypeEnum.FilmToGold:
                                CouponsEntitys = Newtonsoft.Json.JsonConvert.DeserializeObject<List<udv_Coupons>>(Coupons);
                                TotalMoney = ((Gold / 1000) * 100) + CouponsEntitys.Sum(s => s.ba);
                                break;
                            case (int)PaymentTypeEnum.ALL:
                                CouponsEntitys = Newtonsoft.Json.JsonConvert.DeserializeObject<List<udv_Coupons>>(Coupons);
                                TotalMoney = Amount + ((Gold / 1000) * 100) + CouponsEntitys.Sum(s => s.ba);
                                break;
                        }
                        #endregion

                        BetType = Tools.Bet.CheckData(list, TotalMoney, BuyType, TasksDetails, ref IsSplit, ref RetuList);

                        if (BetType == 1)
                        {
                            result = new JsonResult()
                            {
                                Code = (int)ResultCode.BettingMoneyOrderMoneyNoEqual,
                                Msg = Common.GetDescription(ResultCode.BettingMoneyOrderMoneyNoEqual)
                            };
                        }
                        else if (BetType == 2)
                        {
                            result = new JsonResult()
                            {
                                Code = (int)ResultCode.BettingInfoIllegitmacy,
                                Msg = Common.GetDescription(ResultCode.BettingInfoIllegitmacy)
                            };
                        }
                        else
                        {
                            Entity.IsSplit = IsSplit;
                            Random R = new Random();
                            Entity.SchemeNumber = DateTime.Now.ToString("yyyyMMddHHmmssfff") + UserCode + R.Next(1000, 9999);
                            Entity.LotteryNumber = BetData;
                            Entity.LotteryCode = LotteryCode;
                            Entity.SchemeMoney = Amount;
                            Entity.IsuseName = IsuseNum;
                            Entity.InitiateUserID = UserCode;
                            Entity.SchemeID = 0;
                            Entity.BuyType = (byte)BuyType;
                            Entity.RoomCode = RoomCode;

                            long ChaseTaskDetailsID = 0;
                            long SchemeID = dal.SubmitOrder(Entity, RetuList, TasksDetails, CouponsEntitys, PaymentType, Gold, ref ChaseTaskDetailsID);
                            if (SchemeID > 0)
                            {
                                try
                                {

                                    Entity.SchemeID = SchemeID;
                                    #region Redis数据扣费
                                    try
                                    {
                                        new UsersBLL().ModifyUserBalanceRedis(UserCode, Amount, false);
                                    }
                                    catch
                                    {
                                        log.Write(string.Format("余额扣费失败,用户[{0}]扣费{1}失败", UserCode, Amount / 100));
                                    }
                                    #endregion

                                    #region 查询方案详情信息
                                    List<SchemesDetailEntity> SchemesDetailEntits = new SchemesDetailBLL().QueryEntityBySchemeID(SchemeID);
                                    RetuList = SchemesDetailEntits.Select(s => new udv_Parameter()
                                    {
                                        SDID = s.SDID,
                                        Amount = s.BetMoney,
                                        Bet = s.BetNum,
                                        IsNorm = s.IsNorm == 1 ? true : false,
                                        Multiple = s.Multiple,
                                        Number = s.BetNumber,
                                        PlayCode = s.PlayCode,
                                        SchemeID = SchemeID
                                    }).ToList();
                                    #endregion
                                    //生成Redis方案对象
                                    this.GenerateRedisEntity(ChaseTaskDetailsID, Entity, SchemesDetailEntits, ETime);
                                    var UserEntity = new SystemRedis().SignInByUserCodeRedis(UserCode);
                                    ElectronicTicketSender ticket = new ElectronicTicketSender();
                                    ticket.SchemeTicket.SchemeID = SchemeID;
                                    ticket.SchemeTicket.IsRobot = UserEntity.IsRobot;
                                    ticket.SchemeTicket.LotteryCode = Entity.LotteryCode;
                                    ticket.SchemeTicket.StartTime = BTime.ToString("yyyy-MM-dd HH:mm:ss");
                                    ticket.SchemeTicket.EndTime = ETime.ToString("yyyy-MM-dd HH:mm:ss");
                                    ticket.SchemeTicket.IsuseName = Entity.IsuseName;
                                    ticket.SchemeTicket.SchemeMoney = TotalMoney;
                                    ticket.SchemeTicket.TicketDetails = RetuList;
                                    ticket.SchemeTicket.ChaseTaskDetailsID = ChaseTaskDetailsID;
                                    if (!ticket.Sender())
                                    {
                                        //撤单
                                        this.RevokeRedisSchemeEntity(SchemeID, ChaseTaskDetailsID);

                                        result = new JsonResult()
                                        {
                                            Code = (int)ResultCode.IllegalOperation,
                                            Msg = string.Format("投注[订单号为【{0}】,发送拆票系统失败", SchemeID)
                                        };
                                    }
                                    else
                                    {
                                        try
                                        {
                                            string errorinfo = string.Empty;
                                            new IM.Communication().Send_Api_Chatrooms_Bet(UserEntity.Nick, RoomCode, IsuseNum, Common.GetDescription((LotteryInfo)LotteryCode), SchemeID, (byte)BuyType, TotalMoney, UserEntity.AvatarUrl, BetData, ref errorinfo);
                                        }
                                        catch
                                        {
                                            log.Write(string.Format("当前用户[{0}]投注消息发送失败", UserCode));
                                        }
                                        result = new JsonResult()
                                        {
                                            Code = (int)ResultCode.Success,
                                            Msg = Common.GetDescription(ResultCode.Success)
                                        };
                                    }
                                    #region 变更静态数据
                                    Task.Factory.StartNew(() =>
                                    {
                                        new UsersBLL().Staticdata_Buy(Amount, LotteryCode);
                                    });
                                    #endregion
                                }
                                catch (Exception ex)
                                {
                                    result = new JsonResult()
                                    {
                                        Code = (int)ResultCode.IllegalOperation,
                                        Msg = string.Format("投注[订单号为【{0}】,发送拆票系统失败", SchemeID)
                                    };
                                    log.Write("投注：" + ex.StackTrace, true);
                                }
                            }
                            else if (SchemeID == -42) //当期投注参数不正确
                                result = new JsonResult()
                                {
                                    Code = (int)ResultCode.IssueIncorrectParameter,
                                    Msg = Common.GetDescription(ResultCode.IssueIncorrectParameter)
                                };
                            else if (SchemeID == -5)  //未付款订单
                                result = new JsonResult()
                                {
                                    Code = (int)ResultCode.InsufficientBalance,
                                    Msg = Common.GetDescription(ResultCode.InsufficientBalance)
                                };
                            else //系统繁忙
                                result = new JsonResult()
                                {
                                    Code = (int)ResultCode.SystemBusy,
                                    Msg = Common.GetDescription(ResultCode.SystemBusy)
                                };
                        }
                    }
                    catch (Exception ex)
                    {
                        result = new JsonResult()
                        {
                            Code = (int)ResultCode.SystemBusy,
                            Msg = Common.GetDescription(ResultCode.SystemBusy)
                        };
                        log.Write("投注：" + ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Write("投注：" + ex.StackTrace, true);
                result = new JsonResult()
                {
                    Code = (int)ResultCode.SystemBusy,
                    Msg = Common.GetDescription(ResultCode.SystemBusy)
                };
            }
            return result;
        }
        /// <summary>
        /// 跟单投注
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="UserID"></param>
        /// <param name="SchemeID"></param>
        /// <param name="IsuseName"></param>
        /// <returns></returns>
        public JsonResult FollowBet(string Token, long UserCode, long OrderCode, string IsuseName, string BeginTime, string EndTime)
        {
            JsonResult result = null;
            try
            {
                Random R = new Random();
                string SchemeNumber = DateTime.Now.ToString("yyyyMMddHHmmssfff") + UserCode + R.Next(1000, 9999);
                long SchemeID = this.FollowBetting(UserCode, OrderCode, IsuseName, SchemeNumber);
                if (SchemeID > 0)
                {
                    try
                    {
                        DateTime BTime = DateTime.Now, ETime = DateTime.Now;
                        var SchemesEntity = this.QueryEntity(SchemeID);
                        bool IsSuccess = true;
                        try
                        {
                            BTime = DateTime.ParseExact(BeginTime, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                            ETime = DateTime.ParseExact(EndTime, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                        }
                        catch
                        {
                            IsSuccess = false;
                        }
                        if (!IsSuccess)
                        {
                            result = new JsonResult()
                            {
                                Code = (int)ResultCode.RequestHasFailed,
                                Msg = Common.GetDescription(ResultCode.RequestHasFailed)
                            };
                        }
                        else
                        {
                            SchemesEntity Entity = this.QueryEntity(SchemeID);
                            #region Redis数据扣费
                            try
                            {
                                new UsersBLL().ModifyUserBalanceRedis(UserCode, SchemesEntity.SchemeMoney, false);
                            }
                            catch
                            {
                                log.Write(string.Format("余额扣费失败,用户[{0}]扣费{1}失败", UserCode, SchemesEntity.SchemeMoney / 100));
                            }
                            #endregion

                            #region 查询方案详情信息
                            List<SchemesDetailEntity> SchemesDetailEntits = new SchemesDetailBLL().QueryEntityBySchemeID(SchemeID);
                            var RetuList = SchemesDetailEntits.Select(s => new udv_Parameter()
                            {
                                SDID = s.SDID,
                                Amount = s.BetMoney,
                                Bet = s.BetNum,
                                IsNorm = s.IsNorm == 1 ? true : false,
                                Multiple = s.Multiple,
                                Number = s.BetNumber,
                                PlayCode = s.PlayCode,
                                SchemeID = SchemeID
                            }).ToList();
                            #endregion
                            //生成Redis方案对象
                            this.GenerateRedisEntity(0, Entity, SchemesDetailEntits, ETime);
                            var UserEntity = new SystemRedis().SignInByUserCodeRedis(UserCode);
                            ElectronicTicketSender ticket = new ElectronicTicketSender();
                            ticket.SchemeTicket.SchemeID = SchemeID;
                            ticket.SchemeTicket.IsRobot = UserEntity.IsRobot;
                            ticket.SchemeTicket.LotteryCode = Entity.LotteryCode;
                            ticket.SchemeTicket.StartTime = BTime.ToString("yyyy-MM-dd HH:mm:ss");
                            ticket.SchemeTicket.EndTime = ETime.ToString("yyyy-MM-dd HH:mm:ss");
                            ticket.SchemeTicket.IsuseName = Entity.IsuseName;
                            ticket.SchemeTicket.SchemeMoney = Entity.SchemeMoney;
                            ticket.SchemeTicket.TicketDetails = RetuList;
                            ticket.SchemeTicket.ChaseTaskDetailsID = 0;
                            if (!ticket.Sender())
                            {
                                //撤单
                                this.RevokeRedisSchemeEntity(SchemeID, 0);

                                result = new JsonResult()
                                {
                                    Code = (int)ResultCode.IllegalOperation,
                                    Msg = string.Format("跟单投注[订单号为【{0}】,发送拆票系统失败", SchemeID)
                                };
                            }
                            else
                            {
                                try
                                {
                                    string errorinfo = string.Empty;
                                    new IM.Communication().Send_Api_Chatrooms_Bet(UserEntity.Nick, SchemesEntity.RoomCode, IsuseName, Common.GetDescription((LotteryInfo)SchemesEntity.LotteryCode), SchemeID, 2, SchemesEntity.SchemeMoney, UserEntity.AvatarUrl, SchemesEntity.LotteryNumber, ref errorinfo);
                                    #region 变更静态数据
                                    Task.Factory.StartNew(() =>
                                    {
                                        new UsersBLL().Staticdata_Buy(Entity.SchemeMoney, Entity.LotteryCode);
                                    });
                                    #endregion
                                }
                                catch
                                {
                                    log.Write(string.Format("当前用户[{0}]投注消息发送失败", UserCode));
                                }
                                result = new JsonResult()
                                {
                                    Code = (int)ResultCode.Success,
                                    Msg = Common.GetDescription(ResultCode.Success)
                                };
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        result = new JsonResult()
                        {
                            Code = (int)ResultCode.IllegalOperation,
                            Msg = string.Format("跟单投注[订单号为【{0}】,发送拆票系统失败", SchemeID)
                        };
                        log.Write("跟单投注：" + ex.StackTrace, true);
                    }
                }
                else if (SchemeID == -1) //追号不允许跟单
                    result = new JsonResult()
                    {
                        Code = (int)ResultCode.IssueIncorrectParameter,
                        Msg = Common.GetDescription(ResultCode.IssueIncorrectParameter)
                    };
                else if (SchemeID == -2)  //余额不足
                    result = new JsonResult()
                    {
                        Code = (int)ResultCode.InsufficientBalance,
                        Msg = Common.GetDescription(ResultCode.InsufficientBalance)
                    };
                else if (SchemeID == -3)  //当前期已结束
                    result = new JsonResult()
                    {
                        Code = (int)ResultCode.EndIsuseName,
                        Msg = Common.GetDescription(ResultCode.EndIsuseName)
                    };
                else //系统繁忙
                    result = new JsonResult()
                    {
                        Code = (int)ResultCode.SystemBusy,
                        Msg = Common.GetDescription(ResultCode.SystemBusy)
                    };
            }
            catch (Exception ex)
            {
                log.Write("跟单投注：" + ex.StackTrace, true);
                result = new JsonResult()
                {
                    Code = (int)ResultCode.SystemBusy,
                    Msg = Common.GetDescription(ResultCode.SystemBusy)
                };
            }
            return result;
        }
        /// <summary>
        /// 方案列表
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="UserCode"></param>
        /// <param name="OrderStatus"></param>
        /// <param name="PageNumber"></param>
        /// <param name="RowsPerPage"></param>
        /// <returns></returns>
        public SchemeRecordResult SchemeRecord(long UserCode, short OrderStatus, int PageNumber, int RowsPerPage)
        {
            SchemeRecordResult result = null;
            try
            {
                int RecCode = (int)ResultCode.Success;
                List<SchemeRecordEntity> recordData = null;
                switch (OrderStatus)
                {
                    case 1: //待开奖记录
                        recordData = new BusinessRedis().Query_SchemeWaitRedis(UserCode, PageNumber, RowsPerPage);
                        break;
                    case 2: //中奖记录
                        recordData = new BusinessRedis().Query_SchemesWinRedis(UserCode, PageNumber, RowsPerPage);
                        #region 补充查询
                        if (recordData == null || recordData.Count < RowsPerPage || PageNumber > 3)
                        {
                            var replenish_data = dal.QuerySchemeRecord(UserCode, 1, 0, PageNumber, RowsPerPage);
                            if (recordData == null || replenish_data.Count > recordData.Count)
                                if (PageNumber <= 3)
                                    replenish_data.ForEach((Entity) =>
                                    {
                                        var data_entity = new BusinessRedis().Query_SchemeRedis(UserCode, Entity.OrderCode);
                                        if (data_entity == null)
                                            new BusinessRedis().Save_SchemeRedis(UserCode, Entity);
                                        else
                                            new BusinessRedis().Update_SchemeRedis(UserCode, Entity);
                                    });
                            recordData = replenish_data;
                        }
                        #endregion
                        break;
                    case 3: //追号记录
                        recordData = new BusinessRedis().Query_SchemeChase(UserCode, PageNumber, RowsPerPage);
                        #region 补充查询
                        if (recordData == null || recordData.Count < RowsPerPage || PageNumber > 3)
                        {
                            var replenish_data = dal.QuerySchemeRecord(UserCode, 0, 1, PageNumber, RowsPerPage);
                            if (recordData == null || replenish_data.Count > recordData.Count)
                            {
                                if (PageNumber <= 3)
                                    replenish_data.ForEach((Entity) =>
                                    {
                                        var data_entity = new BusinessRedis().Query_SchemeChase(UserCode, Entity.OrderCode);
                                        if (data_entity == null)
                                            new BusinessRedis().Save_SchemeChase(UserCode, Entity);
                                        else
                                            new BusinessRedis().Update_SchemeChase(UserCode, Entity);
                                    });
                                recordData = replenish_data;
                            }
                        }
                        #endregion
                        break;
                    default: //全部订单
                        recordData = new BusinessRedis().Query_SchemeRedis(UserCode, PageNumber, RowsPerPage);
                        #region 补充查询
                        if (recordData == null || recordData.Count < RowsPerPage || PageNumber > 3)
                        {
                            var replenish_data = dal.QuerySchemeRecord(UserCode, 0, 0, PageNumber, RowsPerPage);
                            if (recordData == null || replenish_data.Count > recordData.Count)
                            {
                                if (PageNumber <= 3)
                                    replenish_data.ForEach((Entity) =>
                                    {
                                        var data_entity = new BusinessRedis().Query_SchemeRedis(UserCode, Entity.OrderCode);
                                        if (data_entity == null)
                                            new BusinessRedis().Save_SchemeRedis(UserCode, Entity);
                                        else
                                            new BusinessRedis().Update_SchemeRedis(UserCode, Entity);
                                    });
                                recordData = replenish_data;
                            }
                        }
                        #endregion
                        break;
                }
                if (recordData == null || recordData.Count == 0)
                    RecCode = (int)ResultCode.NullData;

                else
                    RecCode = (int)ResultCode.Success;
                result = new SchemeRecordResult()
                {
                    Code = RecCode,
                    Msg = Common.GetDescription((ResultCode)RecCode),
                    Data = RecCode != (int)ResultCode.Success ? null : recordData
                };
            }
            catch (Exception ex)
            {
                log.Write("方案列表：" + ex.StackTrace, true);
                result = new SchemeRecordResult()
                {
                    Code = (int)ResultCode.SystemBusy,
                    Msg = Common.GetDescription(ResultCode.SystemBusy),
                    Data = null
                };
            }
            return result;
        }

        /// <summary>
        /// 方案详情
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="UserCode"></param>
        /// <param name="OrderCode"></param>
        /// <returns></returns>
        public SchemeDetailResult SchemeDetail(long UserCode, long OrderCode)
        {
            SchemeDetailResult result = null;
            try
            {
                int RecCode = (int)ResultCode.Success;
                SchemeDetailEntity detailData = new BusinessRedis().SchemeDetailRedis(UserCode, OrderCode);
                if (detailData == null)
                {
                    var SchemeEntity = this.QueryEntity(OrderCode);
                    var SchemeWinEntity = new SchemesWinBLL().QueryEntitysBySchemeID(OrderCode);
                    var IsuseEntity = new IsusesBLL().QueryEntity(SchemeEntity.IsuseID);
                    detailData = new SchemeDetailEntity()
                    {
                        Amount = SchemeEntity.SchemeMoney,
                        IsuseNum = SchemeEntity.IsuseName,
                        LotteryCode = SchemeEntity.LotteryCode,
                        LotteryName = Common.GetDescription((LotteryInfo)SchemeEntity.LotteryCode),
                        Number = SchemeEntity.LotteryNumber.Replace(@"\", ""),
                        OrderNum = SchemeEntity.SchemeNumber,
                        OrderStatus = SchemeEntity.SchemeStatus,
                        OrderTime = SchemeEntity.CreateTime.ToString("yyyyMMddHHmmss"),
                        OpenNumber = new IsusesBLL().HandleOpenNumber(SchemeEntity.LotteryCode, IsuseEntity.OpenNumber),
                        WinMoney = SchemeWinEntity == null ? 0 : SchemeWinEntity.Sum(s => s.WinMoneyNoWithTax)
                    };
                }
                else
                {
                    if (string.IsNullOrEmpty(detailData.OpenNumber.Trim()))
                    {
                        var SchemeEntity = this.QueryEntity(OrderCode);
                        var IsuseEntity = new IsusesBLL().QueryEntity(SchemeEntity.IsuseID);
                        if (IsuseEntity != null)
                            detailData.OpenNumber = IsuseEntity.OpenNumber;
                    }
                    var Entitys = detailData;
                    Entitys.OpenNumber = new IsusesBLL().HandleOpenNumber(Entitys.LotteryCode, Entitys.OpenNumber);
                    detailData = Entitys;
                }
                result = new SchemeDetailResult()
                {
                    Code = RecCode,
                    Msg = Common.GetDescription((ResultCode)RecCode),
                    Data = detailData
                };
            }
            catch (Exception ex)
            {
                log.Write("方案详情：" + ex.StackTrace, true);
                result = new SchemeDetailResult()
                {
                    Code = (int)ResultCode.SystemBusy,
                    Msg = Common.GetDescription(ResultCode.SystemBusy)
                };
            }
            return result;
        }
        #endregion

        #region Redis新的处理方式
        #region 服务查询
        /// <summary>
        /// 拆票服务查询方法
        /// </summary>
        /// <param name="SchemeID"></param>
        /// <returns></returns>
        public SchemesEntity QuerySchemeEntity(long SchemeID)
        {
            try
            {
                return dal.QueryEntity(SchemeID);
            }
            catch (Exception ex)
            {
                log.Write("拆票查询方案内容错误[QuerySchemeEntity]：" + ex.ToString(), true);
                return null;
            }
        }
        /// <summary>
        /// 出票服务查询方法
        /// </summary>
        /// <param name="LotteryCode"></param>
        /// <returns></returns>
        public List<udv_OutTickets> QueryOutTicketList(int LotteryCode)
        {
            try
            {
                return new udv_OutTicketsBLL().QueryOutTicketList(LotteryCode);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("出票查询方法错误[QueryOutTicketList]：{0}", ex.StackTrace), true);
                return new udv_OutTicketsBLL().QueryOutTicketList(LotteryCode);
            }
        }
        /// <summary>
        /// 投注服务查询
        /// </summary>
        /// <param name="SchemeID"></param>
        /// <param name="ChaseTaskDetailsID"></param>
        /// <returns></returns>
        public List<udv_BettingTickets> QueryDataList(long SchemeID, long ChaseTaskDetailsID)
        {
            try
            {
                return new udv_BettingTicketsBLL().QueryDataList(SchemeID, ChaseTaskDetailsID);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("投注查询方法错误[QueryDataList]：{0}", ex.StackTrace), true);
                return new udv_BettingTicketsBLL().QueryDataList(SchemeID, ChaseTaskDetailsID);
            }
        }
        /// <summary>
        /// 算奖服务查询：普通
        /// </summary>
        /// <param name="LotteryCode"></param>
        /// <returns></returns>
        public List<udv_ComputeTicket> QueryComputeTicketList(int LotteryCode)
        {
            try
            {
                return new udv_ComputeTicketBLL().QueryComputeTicketList(LotteryCode);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("算奖查询方法错误[QueryComputeTicketList]：{0}", ex.StackTrace), true);
                return new udv_ComputeTicketBLL().QueryComputeTicketList(LotteryCode);
            }
        }
        /// <summary>
        /// 算奖服务查询：追号
        /// </summary>
        /// <param name="LotteryCode"></param>
        /// <returns></returns>
        public List<udv_ComputeTicketChaseTasks> QueryComputeTicketList(int LotteryCode, string ChaseTasksDetail = null)
        {
            try
            {
                return new udv_ComputeTicketChaseTasksBLL().QueryComputeTicketList(LotteryCode);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("算奖查询方法错误[QueryComputeTicketList]：{0}", ex.StackTrace), true);
                return new udv_ComputeTicketChaseTasksBLL().QueryComputeTicketList(LotteryCode);
            }
        }
        #endregion

        #region  生成数据对象保存Redis
        /// <summary>
        /// 生成Redis数据对象
        /// </summary>
        /// <param name="RedisEntity"></param>
        /// <param name="RedisSchemesDetailEntits"></param>
        public void GenerateRedisEntity(long ChaseTaskDetailsID, SchemesEntity RedisEntity, List<SchemesDetailEntity> RedisSchemesDetailEntits, DateTime IsuseEndTime)
        {
            try
            {
                //执行显示
                this.OutApply(RedisEntity.SchemeID, ChaseTaskDetailsID, false, IsuseEndTime);
            }
            catch (Exception ex)
            {
                log.Write(string.Format("生成数据对象错误[GenerateRedisEntity]：{0}", ex.Message), true);
            }
        }
        /// <summary>
        /// 撤单
        /// </summary>
        /// <param name="SchemeID"></param>
        /// <param name="ChaseTaskDetailsID"></param>
        public void RevokeRedisSchemeEntity(long SchemeID, long ChaseTaskDetailsID)
        {
            var RedisEntity = this.QueryEntity(SchemeID);
            if (RedisEntity.BuyType == (byte)BuyTypeEnum.BuyChase)
            {
                List<ChaseTaskDetailsEntity> ChaseTaskDetailsEntitys = new ChaseTaskDetailsBLL().QueryEntitysBySchemeID(SchemeID);
                var ChaseTaskDetailEntity = ChaseTaskDetailsEntitys.Where(w => w.ID == ChaseTaskDetailsID).FirstOrDefault();
                if (ChaseTaskDetailEntity.QuashStatus == (short)QuashStatusEnum.NoQuash)
                {
                    ChaseTaskDetailEntity.QuashStatus = (short)QuashStatusEnum.SysQuash;
                    string IssueName = new IsusesBLL().QueryIssueName(ChaseTaskDetailEntity.IsuseID);
                    new ChaseTaskDetailsBLL().ModifyEntity(ChaseTaskDetailEntity);
                    new UsersBLL().ModifyUserBalanceRedis(RedisEntity.InitiateUserID, ChaseTaskDetailEntity.Amount, true);//撤单
                    new UsersBLL().SendWinMoneyContent(SchemeID, IssueName, ChaseTaskDetailEntity.Amount);//撤单推送
                }
            }
            else
            {
                if (RedisEntity.SchemeStatus != (int)SchemeStatusEnum.OrderRevoke && RedisEntity.SchemeStatus != (int)SchemeStatusEnum.OrderFailure)
                {
                    RedisEntity.SchemeStatus = (int)SchemeStatusEnum.OrderRevoke;
                    this.ModifyEntity(RedisEntity);
                    new UsersBLL().ModifyUserBalanceRedis(RedisEntity.InitiateUserID, RedisEntity.SchemeMoney, true);//撤单
                    new UsersBLL().SendWinMoneyContent(SchemeID, RedisEntity.IsuseName, RedisEntity.SchemeMoney);//撤单推送
                }
            }
            //执行显示
            this.OutApply(RedisEntity.SchemeID, ChaseTaskDetailsID, true, DateTime.Now);
        }
        #endregion

        #region 处理服务逻辑
        /// <summary>
        /// 电子票出票
        /// </summary>
        /// <param name="SchemeIDs"></param>
        /// <param name="SqlPara"></param>
        public void Redis_OutTicket(List<long> SchemeIDs, List<udv_OutTicketEntites> SqlPara)
        {
            SchemeIDs.ForEach((SchemeID) =>
            {
                var TicketEntitys = new SchemeETicketsBLL().QueryEntitysBySchemeID(SchemeID);
                List<long> ChaseTaskDetailEntitys = new List<long>();
                SqlPara.ForEach((item) =>
                {
                    var TicketEntity = TicketEntitys.Where(w => w.SchemeETicketsID == Convert.ToInt64(item.SchemeETicketID)).FirstOrDefault();
                    if (TicketEntity != null)
                        if (!ChaseTaskDetailEntitys.Contains(TicketEntity.ChaseTaskDetailsID))
                            ChaseTaskDetailEntitys.Add(TicketEntity.ChaseTaskDetailsID);
                });
                #region 处理输出内容
                if (ChaseTaskDetailEntitys != null)
                    ChaseTaskDetailEntitys.ForEach((ChaseTaskDetailID) =>
                    {
                        this.OutApply(SchemeID, ChaseTaskDetailID, true, DateTime.Now);
                    });
                #endregion
            });
        }
        /// <summary>
        /// 算奖
        /// </summary>
        /// <param name="ListSql"></param>
        public void Redis_Compute(List<udv_ComputeTicket> ListSql)
        {
            List<long> SchemeIDs = new List<long>();
            ListSql.ForEach((item) =>
            {
                if (!SchemeIDs.Contains(item.SchemeID))
                    SchemeIDs.Add(item.SchemeID);
            });
            SchemeIDs.ForEach((SchemeID) =>
            {
                var Entitys = new SchemeETicketsBLL().QueryWinMoneyListBySchemeID(SchemeID);
                if (Entitys != null && Entitys.Count > 0)
                {
                    var Schemes = this.QueryEntity(SchemeID);
                    if (Schemes != null)
                    {
                        long WinMoney = Entitys.Sum(s => s.WinMoney);
                        if (WinMoney > 0)
                        {
                            #region 开始派奖
                            Task.Factory.StartNew(() =>
                            {
                                new UsersBLL().ModifyUserBalanceRedis(Schemes.InitiateUserID, WinMoney, true);//派奖
                                new SchemesWinBLL().SendWinMoneyContent(SchemeID, WinMoney); //推送中奖
                                new UsersBLL().Staticdata_Aaward(WinMoney, Schemes.LotteryCode); //统计静态数据
                            });
                            #endregion
                        }
                    }
                }
                this.OutApply(SchemeID, 0, true, DateTime.Now);
            });
        }
        /// <summary>
        /// 算奖：追号
        /// </summary>
        /// <param name="ListSql"></param>
        public void Redis_Compute(List<udv_ComputeTicketChaseTasks> ListSql)
        {
            UsersBLL UBLL = new UsersBLL();
            IsusesBLL IBLL = new IsusesBLL();
            SchemesWinBLL WBLL = new SchemesWinBLL();
            ChaseTasksBLL CTBLL = new ChaseTasksBLL();
            SchemesDetailBLL DBLL = new SchemesDetailBLL();
            SchemeETicketsBLL TBLL = new SchemeETicketsBLL();
            ChaseTaskDetailsBLL CBLL = new ChaseTaskDetailsBLL();
            Dictionary<long, long> dic = new Dictionary<long, long>();
            ListSql.ForEach((item) =>
            {
                if (!dic.Keys.Contains(item.SchemeID))
                    dic.Add(item.SchemeID, item.ChaseTaskDetailsID);
            });
            foreach (var SchemeID in dic.Keys)
            {
                long ChaseTaskDetailsID = dic[SchemeID];
                var Entitys = TBLL.QueryWinMoneyListBySchemeID(SchemeID);
                if (Entitys != null && Entitys.Count > 0)
                {
                    var SchemeEntity = this.QueryEntity(SchemeID);
                    long WinMoney = Entitys.Where(w => w.ChaseTaskDetailsID == ChaseTaskDetailsID).Sum(s => s.WinMoney);
                    if (WinMoney > 0)
                    {
                        UBLL.ModifyUserBalanceRedis(SchemeEntity.InitiateUserID, WinMoney, true);//派奖
                        WBLL.SendWinMoneyContent(SchemeID, WinMoney); //推送中奖
                        UBLL.Staticdata_Aaward(WinMoney, SchemeEntity.LotteryCode); //统计静态数据
                    }
                    if (SchemeEntity.BuyType == (byte)BuyTypeEnum.BuyChase)
                    {
                        var ChaseTaskDetailEntitys = CBLL.QueryEntitysBySchemeID(SchemeID);
                        if (ChaseTaskDetailEntitys != null)
                            ChaseTaskDetailEntitys = ChaseTaskDetailEntitys.Where(w => w.IsExecuted == false).ToList();
                        if (ChaseTaskDetailEntitys == null || ChaseTaskDetailEntitys.Count == 0)
                            CBLL.StopChaseTask(SchemeEntity.SchemeID, 0, 0, 1);
                        #region ---------- 中奖停止追号 ----------
                        if (SchemeEntity.SchemeStatus == (short)SchemeStatusEnum.Chaseing)
                        {
                            var ChaseTaskEntity = CTBLL.QueryEntityBySchemeID(SchemeID);
                            //0表示中奖停止;大于0表示累计中奖达到停止
                            if (WinMoney > ChaseTaskEntity.StopTypeWhenWinMoney && ChaseTaskEntity.StopTypeWhenWinMoney != -1)
                            {
                                if (ChaseTaskDetailEntitys != null && ChaseTaskDetailEntitys.Count > 0) //开始撤单
                                {
                                    ChaseTaskDetailEntitys.ForEach((ChaseEntity) =>
                                    {
                                        if (ChaseEntity.QuashStatus == (short)QuashStatusEnum.NoQuash)
                                        {
                                            CBLL.StopChaseTask(SchemeEntity.SchemeID, ChaseEntity.ID, ChaseEntity.Amount, 2); //DB撤单
                                            UBLL.ModifyUserBalanceRedis(SchemeEntity.InitiateUserID, ChaseEntity.Amount, true);//Redis撤单
                                        }
                                        this.OutApply(ChaseEntity.SchemeID, ChaseEntity.ID, true, DateTime.Now);
                                    });
                                }
                            }
                            else
                            {
                                if (ChaseTaskDetailEntitys != null && ChaseTaskDetailEntitys.Count > 0) //开始追号剩余期数
                                {
                                    var ChaseDetailEntity = ChaseTaskDetailEntitys.OrderBy(g => g.ID).FirstOrDefault();
                                    var SchemeDetailEntitys = DBLL.QueryEntityBySchemeID(SchemeID);
                                    var SchemeDetails = SchemeDetailEntitys.Select(s => new udv_Parameter()
                                    {
                                        Amount = ChaseDetailEntity.Amount,
                                        Bet = s.BetNum,
                                        IsNorm = s.IsNorm == 1 ? true : false,
                                        LotteryCode = SchemeEntity.LotteryCode,
                                        Multiple = ChaseDetailEntity.Multiple,
                                        Number = s.BetNumber,
                                        SchemeID = ChaseDetailEntity.SchemeID,
                                        PlayCode = s.PlayCode,
                                        UserCode = SchemeEntity.InitiateUserID,
                                        SDID = s.SDID
                                    }).ToList();
                                    #region 查询即时期次时间
                                    var IsuseEntity = new BusinessRedis().CurrentIsuseRedis(SchemeEntity.LotteryCode);
                                    if (IsuseEntity == null)
                                        IsuseEntity = IBLL.QueryLotteryCurrIsuses(SchemeEntity.LotteryCode);
                                    #endregion
                                    if (IsuseEntity != null && IsuseEntity.IsuseID == ChaseDetailEntity.IsuseID)
                                    {
                                        ElectronicTicketSender ticket = new ElectronicTicketSender();
                                        ticket.SchemeTicket.SchemeID = ChaseDetailEntity.SchemeID;
                                        ticket.SchemeTicket.IsRobot = false; //机器人不允许追号操作
                                        ticket.SchemeTicket.LotteryCode = SchemeEntity.LotteryCode;
                                        ticket.SchemeTicket.StartTime = IsuseEntity.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                                        ticket.SchemeTicket.EndTime = IsuseEntity.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                                        ticket.SchemeTicket.IsuseName = IsuseEntity.IsuseName;
                                        ticket.SchemeTicket.SchemeMoney = ChaseDetailEntity.Amount;
                                        ticket.SchemeTicket.TicketDetails = SchemeDetails;
                                        ticket.SchemeTicket.ChaseTaskDetailsID = ChaseDetailEntity.ID;

                                        if (!ticket.Sender())
                                        {
                                            log.Write("追号电子票发送失败：追号标识[" + ChaseDetailEntity.ID + "]");
                                        }
                                        else
                                        {
                                            ChaseDetailEntity.IsExecuted = true;
                                            CBLL.ModifyEntity(ChaseDetailEntity);
                                        }
                                    }
                                    else
                                    {
                                        var IsusesEntity = IBLL.QueryEntity(ChaseDetailEntity.IsuseID);
                                        ElectronicTicketSender ticket = new ElectronicTicketSender();
                                        ticket.SchemeTicket.SchemeID = ChaseDetailEntity.SchemeID;
                                        ticket.SchemeTicket.IsRobot = false; //机器人不允许追号操作
                                        ticket.SchemeTicket.LotteryCode = SchemeEntity.LotteryCode;
                                        ticket.SchemeTicket.StartTime = IsusesEntity.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                                        ticket.SchemeTicket.EndTime = IsusesEntity.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                                        ticket.SchemeTicket.IsuseName = IsusesEntity.IsuseName;
                                        ticket.SchemeTicket.SchemeMoney = ChaseDetailEntity.Amount;
                                        ticket.SchemeTicket.TicketDetails = SchemeDetails;
                                        ticket.SchemeTicket.ChaseTaskDetailsID = ChaseDetailEntity.ID;

                                        if (!ticket.Sender())
                                        {
                                            log.Write("追号电子票发送失败：追号标识[" + ChaseDetailEntity.ID + "]");
                                        }
                                        else
                                        {
                                            ChaseDetailEntity.IsExecuted = true;
                                            CBLL.ModifyEntity(ChaseDetailEntity);
                                        }
                                    }
                                    this.OutApply(ChaseDetailEntity.SchemeID, ChaseDetailEntity.ID, true, DateTime.Now);
                                }
                            }
                        }
                        #endregion
                    }
                }
                this.OutApply(SchemeID, ChaseTaskDetailsID, true, DateTime.Now);
            }
        }
        /// <summary>
        /// 低频彩派奖(非追号)
        /// </summary>
        /// <param name="SchemeIDs"></param>
        public void Redis_AwardServer(List<udv_WinInfoEntites> SqlPara)
        {
            List<long> SchemeIDs = new List<long>();
            SqlPara.ForEach((item) =>
            {
                if (!SchemeIDs.Contains(item.SchemeID))
                    SchemeIDs.Add(item.SchemeID);
            });
            SchemeIDs.ForEach((SchemeID) =>
            {
                var Entitys = new SchemeETicketsBLL().QueryWinMoneyListBySchemeID(SchemeID);
                if (Entitys != null && Entitys.Count > 0)
                {
                    var Schemes = this.QueryEntity(SchemeID);
                    if (Schemes != null)
                    {
                        if (Schemes.LotteryCode == 801 || Schemes.LotteryCode == 901)
                        {
                            long WinMoney = Entitys.Sum(s => s.WinMoney);
                            if (WinMoney > 0)
                            {
                                #region 开始派奖
                                Task.Factory.StartNew(() =>
                                {
                                    new UsersBLL().ModifyUserBalanceRedis(Schemes.InitiateUserID, WinMoney, true);//派奖
                                    new SchemesWinBLL().SendWinMoneyContent(SchemeID, WinMoney); //推送中奖
                                    new UsersBLL().Staticdata_Aaward(WinMoney, Schemes.LotteryCode); //统计静态数据
                                });
                                #endregion
                            }
                        }
                    }
                    this.OutApply(SchemeID, 0, true, DateTime.Now);
                }
            });
        }
        /// <summary>
        /// 低频彩派奖(追号)
        /// </summary>
        /// <param name="SqlPara"></param>
        public void Redis_AwardServer_Chase(List<udv_WinInfoEntites> SqlPara)
        {
            UsersBLL UBLL = new UsersBLL();
            IsusesBLL IBLL = new IsusesBLL();
            SchemesWinBLL WBLL = new SchemesWinBLL();
            ChaseTasksBLL CTBLL = new ChaseTasksBLL();
            SchemesDetailBLL DBLL = new SchemesDetailBLL();
            SchemeETicketsBLL TBLL = new SchemeETicketsBLL();
            ChaseTaskDetailsBLL CBLL = new ChaseTaskDetailsBLL();
            Dictionary<long, long> dic = new Dictionary<long, long>();
            SqlPara.ForEach((item) =>
            {
                if (!dic.Keys.Contains(item.SchemeID))
                    dic.Add(item.SchemeID, item.ChaseTaskDetailsID);
            });
            foreach (var SchemeID in dic.Keys)
            {
                long ChaseTaskDetailsID = dic[SchemeID];
                var Entitys = TBLL.QueryWinMoneyListBySchemeID(SchemeID);
                if (Entitys != null && Entitys.Count > 0)
                {
                    var SchemeEntity = this.QueryEntity(SchemeID);
                    long WinMoney = Entitys.Where(w => w.ChaseTaskDetailsID == ChaseTaskDetailsID).Sum(s => s.WinMoney);
                    if (WinMoney > 0)
                    {
                        UBLL.ModifyUserBalanceRedis(SchemeEntity.InitiateUserID, WinMoney, true);//派奖
                        WBLL.SendWinMoneyContent(SchemeID, WinMoney); //推送中奖
                        UBLL.Staticdata_Aaward(WinMoney, SchemeEntity.LotteryCode); //统计静态数据
                    }
                    if (SchemeEntity.BuyType == (byte)BuyTypeEnum.BuyChase)
                    {
                        var ChaseTaskDetailEntitys = CBLL.QueryEntitysBySchemeID(SchemeID);
                        if (ChaseTaskDetailEntitys != null)
                            ChaseTaskDetailEntitys = ChaseTaskDetailEntitys.Where(w => w.IsExecuted == false).ToList();
                        if (ChaseTaskDetailEntitys == null || ChaseTaskDetailEntitys.Count == 0)
                            CBLL.StopChaseTask(SchemeEntity.SchemeID, 0, 0, 1);
                        #region ---------- 中奖停止追号 ----------
                        if (SchemeEntity.SchemeStatus == (short)SchemeStatusEnum.Chaseing)
                        {
                            var ChaseTaskEntity = CTBLL.QueryEntityBySchemeID(SchemeID);
                            //0表示中奖停止;大于0表示累计中奖达到停止
                            if (WinMoney > ChaseTaskEntity.StopTypeWhenWinMoney && ChaseTaskEntity.StopTypeWhenWinMoney != -1)
                            {
                                if (ChaseTaskDetailEntitys != null && ChaseTaskDetailEntitys.Count > 0) //开始撤单
                                {
                                    ChaseTaskDetailEntitys.ForEach((ChaseEntity) =>
                                    {
                                        if (ChaseEntity.QuashStatus == (short)QuashStatusEnum.NoQuash)
                                        {
                                            CBLL.StopChaseTask(SchemeEntity.SchemeID, ChaseEntity.ID, ChaseEntity.Amount, 2); //DB撤单
                                            UBLL.ModifyUserBalanceRedis(SchemeEntity.InitiateUserID, ChaseEntity.Amount, true);//Redis撤单
                                        }
                                        this.OutApply(ChaseEntity.SchemeID, ChaseEntity.ID, true, DateTime.Now);
                                    });
                                }
                            }
                            else
                            {
                                if (ChaseTaskDetailEntitys != null && ChaseTaskDetailEntitys.Count > 0) //开始追号剩余期数
                                {
                                    var ChaseDetailEntity = ChaseTaskDetailEntitys.OrderBy(g => g.ID).FirstOrDefault();
                                    var SchemeDetailEntitys = DBLL.QueryEntityBySchemeID(SchemeID);
                                    var SchemeDetails = SchemeDetailEntitys.Select(s => new udv_Parameter()
                                    {
                                        Amount = ChaseDetailEntity.Amount,
                                        Bet = s.BetNum,
                                        IsNorm = s.IsNorm == 1 ? true : false,
                                        LotteryCode = SchemeEntity.LotteryCode,
                                        Multiple = ChaseDetailEntity.Multiple,
                                        Number = s.BetNumber,
                                        SchemeID = ChaseDetailEntity.SchemeID,
                                        PlayCode = s.PlayCode,
                                        UserCode = SchemeEntity.InitiateUserID,
                                        SDID = s.SDID
                                    }).ToList();
                                    #region 查询即时期次时间
                                    var IsuseEntity = new BusinessRedis().CurrentIsuseRedis(SchemeEntity.LotteryCode);
                                    if (IsuseEntity == null)
                                        IsuseEntity = IBLL.QueryLotteryCurrIsuses(SchemeEntity.LotteryCode);
                                    #endregion
                                    if (IsuseEntity != null && IsuseEntity.IsuseID == ChaseDetailEntity.IsuseID)
                                    {
                                        ElectronicTicketSender ticket = new ElectronicTicketSender();
                                        ticket.SchemeTicket.SchemeID = ChaseDetailEntity.SchemeID;
                                        ticket.SchemeTicket.IsRobot = false; //机器人不允许追号操作
                                        ticket.SchemeTicket.LotteryCode = SchemeEntity.LotteryCode;
                                        ticket.SchemeTicket.StartTime = IsuseEntity.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                                        ticket.SchemeTicket.EndTime = IsuseEntity.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                                        ticket.SchemeTicket.IsuseName = IsuseEntity.IsuseName;
                                        ticket.SchemeTicket.SchemeMoney = ChaseDetailEntity.Amount;
                                        ticket.SchemeTicket.TicketDetails = SchemeDetails;
                                        ticket.SchemeTicket.ChaseTaskDetailsID = ChaseDetailEntity.ID;

                                        if (!ticket.Sender())
                                        {
                                            log.Write("追号电子票发送失败：追号标识[" + ChaseDetailEntity.ID + "]");
                                        }
                                        else
                                        {
                                            ChaseDetailEntity.IsExecuted = true;
                                            CBLL.ModifyEntity(ChaseDetailEntity);
                                        }
                                    }
                                    else
                                    {
                                        var IsusesEntity = IBLL.QueryEntity(ChaseDetailEntity.IsuseID);
                                        ElectronicTicketSender ticket = new ElectronicTicketSender();
                                        ticket.SchemeTicket.SchemeID = ChaseDetailEntity.SchemeID;
                                        ticket.SchemeTicket.IsRobot = false; //机器人不允许追号操作
                                        ticket.SchemeTicket.LotteryCode = SchemeEntity.LotteryCode;
                                        ticket.SchemeTicket.StartTime = IsusesEntity.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                                        ticket.SchemeTicket.EndTime = IsusesEntity.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                                        ticket.SchemeTicket.IsuseName = IsusesEntity.IsuseName;
                                        ticket.SchemeTicket.SchemeMoney = ChaseDetailEntity.Amount;
                                        ticket.SchemeTicket.TicketDetails = SchemeDetails;
                                        ticket.SchemeTicket.ChaseTaskDetailsID = ChaseDetailEntity.ID;

                                        if (!ticket.Sender())
                                        {
                                            log.Write("追号电子票发送失败：追号标识[" + ChaseDetailEntity.ID + "]");
                                        }
                                        else
                                        {
                                            ChaseDetailEntity.IsExecuted = true;
                                            CBLL.ModifyEntity(ChaseDetailEntity);
                                        }
                                    }
                                    this.OutApply(ChaseDetailEntity.SchemeID, ChaseDetailEntity.ID, true, DateTime.Now);
                                }
                            }
                        }
                        #endregion

                    }
                }
                this.OutApply(SchemeID, ChaseTaskDetailsID, true, DateTime.Now);
            }
        }

        #region 前端显示处理
        /// <summary>
        /// 应用输出内容
        /// </summary>
        /// <param name="SchemeID"></param>
        /// <param name="ChaseTaskDetailsID"></param>
        public void OutApply(long SchemeID, long ChaseTaskDetailsID, bool IsModify, DateTime IsuseEndTime)
        {
            try
            {
                SchemeRecordEntity Redis_SchemeRecordEntity = null;
                SchemeDetailEntity Redis_SchemeDetailEntity = null;
                ChaseDetailEntity Redis_ChaseDetailEntity = null;
                ChaseRecordEntity Redis_ChaseRecordEntity = null;
                BusinessRedis businessRedis = new BusinessRedis();
                var SchemeEntity = this.QueryEntity(SchemeID);
                if (SchemeEntity == null)
                    return;
                if (!IsModify)
                {
                    #region 创建对象
                    #region 方案列表
                    Redis_SchemeRecordEntity = new SchemeRecordEntity()
                    {
                        Amount = SchemeEntity.SchemeMoney,
                        BuyType = SchemeEntity.BuyType,
                        LotteryName = Common.GetDescription((LotteryInfo)SchemeEntity.LotteryCode),
                        OrderCode = SchemeID,
                        OrderStatus = SchemeEntity.SchemeStatus,
                        OrderTime = DateTime.Now.ToString("yyyyMMddHHmmss"),
                        WinMoney = 0,
                        IsuseNum = SchemeEntity.BuyType == (byte)BuyTypeEnum.BuyChase ? string.Empty : SchemeEntity.IsuseName
                    };
                    //全部方案信息
                    businessRedis.Save_SchemeRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                    //待开奖方案信息
                    businessRedis.Save_SchemeWaitRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                    #endregion
                    if (SchemeEntity.BuyType == (byte)BuyTypeEnum.BuyChase)
                    {
                        var ChaseTaskDetailEntitys = new ChaseTaskDetailsBLL().QueryEntitysBySchemeID(SchemeID);

                        var ChaseTaskEntity = new ChaseTasksBLL().QueryEntityBySchemeID(SchemeID);

                        #region 追号记录
                        var Data_Already = ChaseTaskDetailEntitys.Where(w => w.IsExecuted == true).Select(s => new AlreadyEntity()
                        {
                            Amount = s.Amount,
                            ChaseDetailCode = s.ID,
                            ChaseStatus = s.QuashStatus == (short)QuashStatusEnum.NoQuash ? "下单成功,投注站出票中" : "撤单",
                            IsuseNum = new IsusesBLL().QueryIssueName(s.IsuseID),
                            WinMoney = 0
                        }).OrderBy(o => o.ChaseDetailCode).ToList();
                        var Data_Surplus = ChaseTaskDetailEntitys.Where(w => w.IsExecuted == false).Select(s => new SurplusEntity()
                        {
                            Amount = s.Amount,
                            ChaseDetailCode = s.ID,
                            ChaseStatus = "等待追号",
                            IsuseNum = new IsusesBLL().QueryIssueName(s.IsuseID)
                        }).OrderBy(o => o.ChaseDetailCode).ToList();
                        Redis_ChaseRecordEntity = new ChaseRecordEntity()
                        {
                            Already = Data_Already.Count(),
                            AlreadyData = Data_Already,
                            Amount = SchemeEntity.SchemeMoney,
                            IsuseCount = ChaseTaskEntity.IsuseCount,
                            LotteryCode = SchemeEntity.LotteryCode,
                            LotteryName = Common.GetDescription((LotteryInfo)SchemeEntity.LotteryCode),
                            Number = SchemeEntity.LotteryNumber,
                            OrderStatus = SchemeEntity.SchemeStatus,
                            Stops = ChaseTaskEntity.StopTypeWhenWinMoney,
                            WinMoney = 0,
                            Surplus = Data_Surplus.Count(),
                            SurplusData = Data_Surplus
                        };
                        businessRedis.ChaseRecordRedis(SchemeEntity.InitiateUserID, SchemeID, Redis_ChaseRecordEntity);
                        #endregion
                        #region 追号详情
                        ChaseTaskDetailEntitys.ForEach((item) =>
                        {
                            Redis_ChaseDetailEntity = new ChaseDetailEntity()
                            {
                                Amount = item.Amount,
                                IsOpened = false,
                                IsuseNum = new IsusesBLL().QueryIssueName(item.IsuseID),
                                LotteryCode = SchemeEntity.LotteryCode,
                                Number = SchemeEntity.LotteryNumber,
                                OpenNumber = string.Empty,
                                OrderNum = SchemeEntity.SchemeNumber, //方案号
                                OrderStatus = item.QuashStatus == (short)QuashStatusEnum.NoQuash ? 2 : 3, //0未中奖 1中奖 2下单成功,等待出票 3撤单 4出票成功,等待开奖
                                OrderTime = DateTime.Now.ToString("yyyyMMddHHmmss"),
                                WinMoney = 0
                            };
                            businessRedis.ChaseDetailRedis(SchemeEntity.InitiateUserID, item.ID, Redis_ChaseDetailEntity);
                        });
                        #endregion
                        #region 追号列表
                        businessRedis.Save_SchemeChase(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                        #endregion
                    }
                    else
                    {
                        #region 方案详情
                        Redis_SchemeDetailEntity = new SchemeDetailEntity()
                        {
                            Amount = SchemeEntity.SchemeMoney,
                            IsuseNum = SchemeEntity.IsuseName,
                            LotteryCode = SchemeEntity.LotteryCode,
                            LotteryName = Common.GetDescription((LotteryInfo)SchemeEntity.LotteryCode),
                            Number = SchemeEntity.LotteryNumber,
                            OpenNumber = string.Empty,
                            OrderNum = SchemeEntity.SchemeNumber,
                            OrderStatus = SchemeEntity.SchemeStatus,
                            OrderTime = DateTime.Now.ToString("yyyyMMddHHmmss"),
                            WinMoney = 0,
                            RoomID = SchemeEntity.RoomCode
                        };
                        businessRedis.SchemeDetailRedis(SchemeEntity.InitiateUserID, SchemeID, Redis_SchemeDetailEntity);
                        #endregion
                    }

                    #endregion
                }
                else
                {
                    //订单状态 0待付款，2.订单过期，4下单成功，6.出票成功，8.部分出票成功，10.下单失败（限号），12.订单撤销，14.中奖，15.派奖中，16.派奖完成，18.不中奖完成，19.追号进行中，20.追号完成
                    #region 更新对象
                    var SchemeETicketEntitys = new SchemeETicketsBLL().QueryWinMoneyListBySchemeID(SchemeID);
                    Redis_SchemeRecordEntity = businessRedis.Query_SchemeRedis(SchemeEntity.InitiateUserID, SchemeID);
                    if (Redis_SchemeRecordEntity == null)
                        return;
                    long WinMoney = SchemeETicketEntitys.Sum(s => s.WinMoney);
                    Redis_SchemeRecordEntity.OrderStatus = SchemeEntity.SchemeStatus;
                    Redis_SchemeRecordEntity.WinMoney = WinMoney;
                    if (SchemeEntity.SchemeStatus == (short)SchemeStatusEnum.OrderFailure || SchemeEntity.SchemeStatus == (short)SchemeStatusEnum.OrderRevoke || SchemeEntity.SchemeStatus == (short)SchemeStatusEnum.Winning || SchemeEntity.SchemeStatus == (short)SchemeStatusEnum.NoWinningSuccess)
                    {
                        businessRedis.Update_SchemeRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                        businessRedis.Remove_SchemeWaitRedis(SchemeEntity.InitiateUserID, SchemeID);
                        if (SchemeEntity.SchemeStatus == (short)SchemeStatusEnum.Winning && WinMoney > 0)
                        {
                            Redis_SchemeRecordEntity.IsuseNum = SchemeEntity.IsuseName;
                            businessRedis.Save_SchemesWinRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                        }
                    }
                    else
                    {
                        businessRedis.Update_SchemeRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                        var SchemeRecordWaitEntity = businessRedis.Query_SchemeWaitRedis(SchemeEntity.InitiateUserID, SchemeEntity.SchemeID);
                        if (SchemeRecordWaitEntity != null)
                            businessRedis.Save_SchemeWaitRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                    }

                    if (SchemeEntity.BuyType == (byte)BuyTypeEnum.BuyChase)
                    {
                        if (SchemeEntity.SchemeStatus == (short)SchemeStatusEnum.ChaseSuccess)
                        {
                            businessRedis.Update_SchemeRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                            businessRedis.Update_SchemeChase(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                            businessRedis.Remove_SchemeWaitRedis(SchemeEntity.InitiateUserID, SchemeID);
                            if (WinMoney > 0)
                            {
                                businessRedis.Save_SchemesWinRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                            }
                        }
                        else
                        {
                            businessRedis.Update_SchemeRedis(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                            businessRedis.Update_SchemeChase(SchemeEntity.InitiateUserID, Redis_SchemeRecordEntity);
                        }
                        var ChaseTaskDetailEntitys = new ChaseTaskDetailsBLL().QueryEntitysBySchemeID(SchemeID);
                        var ChaseTaskEntity = new ChaseTasksBLL().QueryEntityBySchemeID(SchemeID);
                        #region 追号记录
                        var Data_Already = ChaseTaskDetailEntitys.Where(w => w.IsExecuted == true).Select(s => new AlreadyEntity()
                        {
                            Amount = s.Amount,
                            ChaseDetailCode = s.ID,
                            ChaseStatus = this.SetChaseStatus[this.ChaseStatus(SchemeETicketEntitys, s.ID)],
                            IsuseNum = new IsusesBLL().QueryIssueName(s.IsuseID), //待维护
                            WinMoney = SchemeETicketEntitys.Where(w => w.ChaseTaskDetailsID == s.ID).Sum(so => so.WinMoney)
                        }).OrderBy(o => o.ChaseDetailCode).ToList();
                        var Data_Surplus = ChaseTaskDetailEntitys.Where(w => w.IsExecuted == false).Select(s => new SurplusEntity()
                        {
                            Amount = s.Amount,
                            ChaseDetailCode = s.ID,
                            ChaseStatus = s.QuashStatus == (short)QuashStatusEnum.NoQuash ? "等待追号" : "撤单",
                            IsuseNum = new IsusesBLL().QueryIssueName(s.IsuseID)
                        }).OrderBy(o => o.ChaseDetailCode).ToList();
                        Redis_ChaseRecordEntity = new ChaseRecordEntity()
                        {
                            Already = Data_Already.Count(),
                            AlreadyData = Data_Already,
                            Amount = SchemeEntity.SchemeMoney,
                            IsuseCount = ChaseTaskEntity.IsuseCount,
                            LotteryCode = SchemeEntity.LotteryCode,
                            LotteryName = Common.GetDescription((LotteryInfo)SchemeEntity.LotteryCode),
                            Number = SchemeEntity.LotteryNumber,
                            OrderStatus = SchemeEntity.SchemeStatus,
                            Stops = ChaseTaskEntity.StopTypeWhenWinMoney,
                            WinMoney = WinMoney,
                            Surplus = Data_Surplus.Count(),
                            SurplusData = Data_Surplus
                        };
                        businessRedis.ChaseRecordRedis(SchemeEntity.InitiateUserID, SchemeID, Redis_ChaseRecordEntity);
                        #endregion
                        #region 追号详情
                        ChaseTaskDetailEntitys.ForEach((item) =>
                        {
                            long WinMoney_Detail = SchemeETicketEntitys.Where(w => w.ChaseTaskDetailsID == item.ID).Sum(s => s.WinMoney);
                            bool IsOpened = false;
                            string IsusesName = new IsusesBLL().QueryIssueName(item.IsuseID);
                            var OpenIsuseEntity = businessRedis.OfLotteryDetailRedis(SchemeEntity.LotteryCode, IsusesName);
                            if (OpenIsuseEntity != null && !string.IsNullOrEmpty(OpenIsuseEntity.OpenNumber))
                                IsOpened = true;
                            Redis_ChaseDetailEntity = new ChaseDetailEntity()
                            {
                                Amount = item.Amount,
                                IsOpened = IsOpened,
                                IsuseNum = new IsusesBLL().QueryIssueName(item.IsuseID), //待维护
                                LotteryCode = SchemeEntity.LotteryCode,
                                Number = SchemeEntity.LotteryNumber,
                                OpenNumber = OpenIsuseEntity == null ? string.Empty : OpenIsuseEntity.OpenNumber,
                                OrderNum = SchemeEntity.SchemeNumber, //方案号
                                OrderStatus = this.ChaseStatus(SchemeETicketEntitys, item.ID),
                                OrderTime = item.CreateTime.ToString("yyyyMMddHHmmss"),
                                WinMoney = WinMoney_Detail
                            };
                            businessRedis.ChaseDetailRedis(SchemeEntity.InitiateUserID, item.ID, Redis_ChaseDetailEntity);
                        });
                        #endregion
                    }
                    else
                    {
                        #region 方案详情
                        Redis_SchemeDetailEntity = businessRedis.SchemeDetailRedis(SchemeEntity.InitiateUserID, SchemeID);
                        Redis_SchemeDetailEntity.WinMoney = WinMoney;
                        Redis_SchemeDetailEntity.OrderStatus = SchemeEntity.SchemeStatus;
                        Redis_SchemeDetailEntity.RoomID = SchemeEntity.RoomCode;
                        businessRedis.SchemeDetailRedis(SchemeEntity.InitiateUserID, SchemeID, Redis_SchemeDetailEntity);
                        #endregion
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                log.Write(string.Format("应用输出内容[OutApply]：{0}", ex.Message), true);
            }
        }
        /// <summary>
        /// 追号状态
        /// </summary>
        /// <param name="ChaseTaskDetailsID"></param>
        /// <returns></returns>
        string[] SetChaseStatus = new string[] { "未中奖", "中奖", "下单成功,投注站出票中", "撤单", "出票成功,等待开奖", "部分出票成功" };
        protected int ChaseStatus(List<cv_Ticket> TicketEntitys, long ChasedetailID)
        {
            TicketEntitys = TicketEntitys.Where(w => w.ChaseTaskDetailsID == ChasedetailID).ToList();
            int rec = 2;  //0未中奖 1中奖 2下单成功,投注站出票中 3撤单 4出票成功,等待开奖,5部分出票成功
            if (TicketEntitys == null || TicketEntitys.Count == 0)
                rec = 3;
            else
            {
                int WinLength = TicketEntitys.Where(w => w.TicketStatus == (byte)TicketStatusEnum.Winning).Count();
                if (WinLength > 0)
                    rec = 1;
                else
                {
                    int NotWinLength = TicketEntitys.Where(w => w.TicketStatus == (byte)TicketStatusEnum.NoWinning).Count();
                    if (NotWinLength > 0)
                        rec = 0;
                    else
                    {
                        int BetLength = TicketEntitys.Where(w => w.TicketStatus == 1).Count();
                        if (BetLength > 0)
                            rec = 2;
                        else
                        {
                            int FailLength = TicketEntitys.Where(w => w.TicketStatus == (byte)TicketStatusEnum.BettingFailure || w.TicketStatus == (byte)TicketStatusEnum.InTickeFailure).Count();
                            if (TicketEntitys.Count == FailLength)
                                rec = 3;
                            else
                            {
                                int SuccessLength = TicketEntitys.Where(w => w.TicketStatus == (byte)TicketStatusEnum.InTickeSuccess).Count();
                                if (TicketEntitys.Count == SuccessLength)
                                    rec = 4;
                                else
                                    rec = 5;
                            }
                        }
                    }
                }
            }
            return rec;
        }

        #endregion
        #endregion

        #endregion
    }
}
